package com.tueye.web.controller.usermanager;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tueye.entity.Topics;
import com.tueye.entity.user.User;
import com.tueye.entity.user.UserCollectionInfo;
import com.tueye.service.ITopicService;
import com.tueye.service.usermanager.IUserTopicManager;
import com.tueye.utils.DateUtils;
import com.tueye.utils.SystemContext;
import com.tueye.utils.TuEyeConstant;
import com.tueye.utils.UUIDGenerator;
import com.tueye.utils.servlet.CaptchaServiceSingleton;
import com.tueye.web.controller.BaseController;
import com.tueye.web.controller.blog.PagerModel;

@SuppressWarnings("unchecked")
@Controller
public class UserCollectController extends BaseController {
	private Log log = LogFactory.getLog(UserCollectController.class);
	
	@Autowired
	@Qualifier("userTopicManger")
	IUserTopicManager userTopicManger;
	@Autowired
	@Qualifier("topicService")
	ITopicService topicService;
 
	@RequestMapping("/usercollect.do")
	public String topic (HttpServletRequest request, HttpServletResponse response) throws Exception {
		User user =  (User) request.getSession().getAttribute(TuEyeConstant.TUEYE_USER);
        if(user  == null){
        	 return "pages/topics/usermanager/userlogin";  
        }
		 String target ="/pages/topics/usermanager/usercollect";
		 String hql = "select t.topics from UserCollectionInfo t where t.userTopicType = 2 and t.user.id='"+user.getId() +"'";
		 PagerModel pm =  userTopicManger.getAllTopicByUserId(hql, SystemContext.getOffset(), SystemContext.getPagesize());
		 
		 request.setAttribute("pm", pm);
		 return target; 
		
	}
	
	@RequestMapping("/delcollect.do")
	public String delcollect (HttpServletRequest request, HttpServletResponse response) throws Exception {
		 User user =  (User) request.getSession().getAttribute(TuEyeConstant.TUEYE_USER);
         String userId = user.getId();
         String topicid = request.getParameter("del_id");
         userTopicManger.delcollect(userId,topicid);
         response.getWriter().write("true");
		 return null; 
		
	}
	 

}
